package com.example.cms.controller;

import com.example.cms.entity.Questionnaired;
import com.example.cms.entity.Questionnairefile;
import com.example.cms.pojo.Mesagge;
import com.example.cms.service.QuestionnairedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ClassName QuestionTitleItemContorller
 * @Descriptiom TODO
 * @Author Sunbird
 * @Date 2018/12/21 11:18
 * @Version 1.0
 **/
@RestController
public class QuestionTitleItemContorller {
    @Autowired
    private QuestionnairedService questionnairedService;
    /**
     * @Author Sunbird
     * @Description 查询所有的表
     * @Date  2018/12/18
     * @Param
     * @return
     **/
    @RequestMapping("naired")
    public List QuestionNaired(){
        List<Questionnaired> list= questionnairedService.getAllQues();
        return list;
    }
    /**
     * @Author Sunbird
     * @Description 根据id查询题目
     * @Date  2018/12/19
     * @Param
     * @return
     **/
    @RequestMapping("nairedById")
    public List<Questionnaired> SelectQuestionNairde(Integer questionNairedid){
        List<Questionnaired> list =questionnairedService.findeQuestionNaireId(questionNairedid);
        return  list;
    }
    /**
     * @Author Sunbird
     * @Description 删除问卷信息
     * @Date  2018/12/20
     * @Param
     * @return
     **/
    @RequestMapping("deletQuestion")
    public Mesagge deletQuestionNaired(Integer QuestionNairedId ,Mesagge mesagge){
        return questionnairedService.deletQuestionNaired(QuestionNairedId,mesagge);
    }
    /**
     * @Author Sunbird
     * @Description 新增试卷
     * @Date  2018/12/20
     * @Param
     * @return
     **/
    @RequestMapping("insertQuest")
    public Mesagge insertQuestionNaired(Questionnaired questionnaired, Mesagge mesagge, HttpServletRequest request){
if (questionnaired==null&& ("").equals(questionnaired)){
       mesagge.setMesCode(404);
        return mesagge;
}else {
    String name = request.getParameter("questionNairedName");
    System.out.println(name);
    System.out.println(questionnaired.toString());
    questionnairedService.insertQuestionNaired(questionnaired, mesagge);
    return mesagge;
}
}
    @RequestMapping("insertTitle")
    public Mesagge insertTitle(Questionnaired questionnaired ,Mesagge mesagge){
        questionnairedService.insertQuestTitle(questionnaired,mesagge);
        return mesagge;
    }

    @RequestMapping("insertOption")
    public Mesagge insertQuestTitle(Questionnairefile questionnairefile, Mesagge mesagge){
        questionnairedService.insertOptions(mesagge,questionnairefile);
        return mesagge;
    }

    /**
     * @Author Sunbird
     * @Description 查询题目名称
     * @Date  2018/12/23
     * @Param
     * @return
     **/
    @RequestMapping("selectQuestionName")
    public List selectQuestionName(String questionName){
        return questionnairedService.selectQuestionName(questionName);
    }


    /**
     * @Author Sunbird
     * @Description 删除选项
     * @Date  2018/12/23
     * @Param
     * @return
     **/
    @RequestMapping("deletOption")
    public  Mesagge deletQuestionOption(Mesagge mesagge,Integer ids){
            questionnairedService.detleOptions(mesagge,ids);
          return mesagge;
    }


    @RequestMapping("deletTitle")
    public  Mesagge deletQuestionTitle(Mesagge mesagge,Integer ids){
        questionnairedService.deletQuestTitle(ids,mesagge);
        return mesagge;
    }
//    public Mesagge inserOption(){
//
//    }
}
